{% block sw_settings_currency_detail %}
<sw-page class="sw-settings-currency-detail">

    {% block sw_settings_currency_detail_header %}
    <template #smart-bar-header>
        <h2>{{ placeholder(currency, 'name', $tc('sw-settings-currency.detail.textHeadline')) }}</h2>
    </template>
    {% endblock %}

    {% block sw_settings_currency_detail_actions %}
    <template #smart-bar-actions>
        {% block sw_settings_currency_detail_actions_abort %}
        <mt-button
            v-tooltip.bottom="tooltipCancel"
            :disabled="isLoading"
            variant="secondary"
            size="default"
            @click="onCancel"
        >
            {{ $tc('global.default.cancel') }}
        </mt-button>
        {% endblock %}

        {% block sw_settings_currency_detail_actions_save %}
        <sw-button-process
            v-model:process-success="isSaveSuccessful"
            v-tooltip.bottom="tooltipSave"
            class="sw-settings-currency-detail__save-action"
            :is-loading="isLoading"
            :disabled="isLoading || !acl.can('currencies.editor') || undefined"
            variant="primary"
            @update:process-success="saveFinish"
            @click.prevent="onSave"
        >
            {{ $tc('sw-settings-currency.detail.buttonSave') }}
        </sw-button-process>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_settings_currency_detail_language_switch %}
    <template #language-switch>
        <sw-language-switch
            :disabled="currencyId == null"
            :save-changes-function="saveOnLanguageChange"
            :abort-change-function="abortOnLanguageChange"
            @on-change="onChangeLanguage"
        />
    </template>
    {% endblock %}

    {% block sw_settings_currency_detail_content %}
    <template #content>
        <sw-card-view>

            <template v-if="isLoading">
                <sw-skeleton />
                <sw-skeleton />
            </template>

            <template v-else>
                {% block sw_settings_currency_detail_content_language_info %}
                <sw-language-info
                    :entity-description="placeholder(currency, 'name', $tc('sw-settings-currency.detail.textHeadline'))"
                />
                {% endblock %}

                {% block sw_settings_currency_detail_content_card %}
                <mt-card
                    position-identifier="sw-settings-currency-detail-content"
                    :is-loading="isLoading"
                    :title="$tc('sw-settings-currency.detail.titleCard')"
                >
                    <sw-container
                        columns="repeat(auto-fit, minmax(250px, 1fr))"
                        gap="0px 30px"
                    >

                        {% block sw_settings_currency_detail_content_field_name %}

                        <mt-text-field
                            v-model="currency.name"
                            name="sw-field--currency-name"
                            required
                            :disabled="!acl.can('currencies.editor')"
                            :label="$tc('sw-settings-currency.detail.labelName')"
                            :placeholder="placeholder(currency, 'name', $tc('sw-settings-currency.detail.placeholderName'))"
                            :error="currencyNameError"
                        />
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_field_iso_code %}

                        <mt-text-field
                            v-model="currency.isoCode"
                            name="sw-field--currency-isoCode"
                            required
                            :disabled="!acl.can('currencies.editor')"
                            :label="$tc('sw-settings-currency.detail.labelIsoCode')"
                            :placeholder="placeholder(currency, 'isoCode', $tc('sw-settings-currency.detail.placeholderIsoCode'))"
                            :error="currencyIsoCodeError"
                        />
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_field_short_name %}

                        <mt-text-field
                            v-model="currency.shortName"
                            name="sw-field--currency-shortName"
                            required
                            :disabled="!acl.can('currencies.editor')"
                            :label="$tc('sw-settings-currency.detail.labelShortName')"
                            :placeholder="placeholder(currency, 'shortName', $tc('sw-settings-currency.detail.placeholderShortName'))"
                            :error="currencyShortNameError"
                        />
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_field_symbol %}

                        <mt-text-field
                            v-model="currency.symbol"
                            name="sw-field--currency-symbol"
                            required
                            :disabled="!acl.can('currencies.editor')"
                            :label="$tc('sw-settings-currency.detail.labelSymbol')"
                            :placeholder="$tc('sw-settings-currency.detail.placeholderSymbol')"
                            :error="currencySymbolError"
                        />
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_field_factor %}
                        <mt-number-field
                            v-model="currency.factor"
                            name="sw-field--currency-factor"
                            required
                            :digits="14"
                            :label="$tc('sw-settings-currency.detail.labelFactor')"
                            :placeholder="$tc('sw-settings-currency.detail.placeholderFactor')"
                            :error="currencyFactorError"
                            :disabled="currency.isSystemDefault || !acl.can('currencies.editor')"
                        />
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_field_tax_free_from %}
                        <mt-number-field
                            v-model="currency.taxFreeFrom"
                            name="sw-field--currency-taxFreeFrom"
                            :min="0"
                            :label="$tc('sw-settings-currency.detail.taxFreeFrom')"
                            :help-text="$tc('sw-settings-currency.detail.taxFreeFromHelpText', { currencyName: `${currency.name}` }, 0)"
                            :disabled="!currency.factor"
                        >
                            <template #suffix>
                                {{ currency.symbol }}
                            </template>
                        </mt-number-field>
                        {% endblock %}

                    </sw-container>
                </mt-card>
                {% endblock %}

                {% block sw_settings_currency_detail_content_card_price_rounding %}
                <mt-card
                    position-identifier="sw-settings-currency-detail-price-rounding"
                    :is-loading="isLoading"
                    :title="$tc('sw-settings-currency.detail.titleRoundingCard')"
                >
                    <sw-settings-price-rounding
                        :item-rounding="currency.itemRounding"
                        :total-rounding="currency.totalRounding"
                    />
                </mt-card>
                {% endblock %}

                {% block sw_settings_currency_detail_content_card_country_price_rounding %}
                <mt-card
                    position-identifier="sw-settings-currency-detail-country-price-rounding"
                    :title="$tc('sw-settings-currency.detail.titleCountryRoundingCard')"
                    :is-loading="currencyCountryLoading"
                >
                    <template
                        v-if="currency.id && !currency.isNew()"
                        #toolbar
                    >
                        {% block sw_settings_currency_detail_content_card_country_price_rounding_toolbar %}
                        <div class="sw-settings-currency-detail__currency-country-toolbar">
                            {% block sw_settings_currency_detail_content_card_country_price_rounding_toolbar_filter %}
                            <sw-card-filter
                                :placeholder="$tc('sw-settings-currency.detail.searchbarPlaceholder')"
                                @sw-card-filter-term-change="onChangeCountrySearch"
                            />
                            {% endblock %}
                            {% block sw_settings_currency_detail_content_card_country_price_rounding_toolbar_button %}
                            <mt-button
                                ghost
                                class="sw-settings-currency-detail__currency-country-toolbar-button"
                                size="small"
                                variant="secondary"
                                @click="onAddCountry"
                            >
                                {{ $tc('sw-settings-currency.detail.buttonAddCountry') }}
                            </mt-button>
                            {% endblock %}
                        </div>
                        {% endblock %}
                    </template>
                    {% block sw_settings_currency_detail_content_card_country_price_rounding_listing %}
                    <sw-entity-listing
                        v-if="currencyCountryRoundings && currencyCountryRoundings.length > 0"
                        class="sw-settings-currency-detail__currency-country-list"
                        :full-page="false"
                        :show-selection="false"
                        :items="currencyCountryRoundings"
                        :columns="currencyCountryColumns"
                        identifier="sw-settings-currency-detail-currency-country-list"
                        :repository="currencyCountryRoundingRepository"
                        @delete-item-finish="loadCurrencyCountryRoundings"
                        @items-delete-finish="loadCurrencyCountryRoundings"
                    >
                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_country_column %}
                        <template #column-country="{ item }">
                            <a
                                href="#"
                                @click="onClickEdit(item)"
                            >
                                {{ item.country.name }}
                            </a>
                        </template>
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_item_interval_column %}
                        <template #column-itemRounding.interval="{ item }">
                            <template v-if="item.itemRounding.interval === 0.01">
                                {{ $tc('sw-settings-currency.price-rounding.labelIntervalNone') }}
                            </template>
                            <template v-if="item.itemRounding.interval !== 0.01">
                                {{ item.itemRounding.interval }}
                            </template>
                        </template>
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_total_interval_column %}
                        <template #column-totalRounding.interval="{ item }">
                            <template v-if="item.totalRounding.interval === 0.01">
                                {{ $tc('sw-settings-currency.price-rounding.labelIntervalNone') }}
                            </template>
                            <template v-if="item.totalRounding.interval !== 0.01">
                                {{ item.totalRounding.interval }}
                            </template>
                        </template>
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_item_net_column %}
                        <template #column-itemRounding.roundForNet="{ item }">
                            <sw-data-grid-column-boolean v-model:value="item.itemRounding.roundForNet" />
                        </template>
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_total_net_column %}
                        <template #column-totalRounding.roundForNet="{ item }">
                            <sw-data-grid-column-boolean v-model:value="item.totalRounding.roundForNet" />
                        </template>
                        {% endblock %}

                        {% block sw_settings_currency_detail_content_card_country_price_rounding_listing_more_actions %}
                        <template #more-actions="{ item }">
                            <sw-context-menu-item @click="onClickEdit(item)">
                                {{ $tc('global.default.edit') }}
                            </sw-context-menu-item>
                        </template>
                        {% endblock %}

                    </sw-entity-listing>
                    {% endblock %}

                    {% block sw_settings_currency_detail_content_card_country_price_rounding_empty %}
                    <mt-empty-state
                        v-else
                        class="sw-settings-currency-detail__currency-country-empty-state"
                        :icon="$route.meta.$module.icon"
                        :headline="emptyStateText"
                    />
                    {% endblock %}
                </mt-card>
                {% block sw_settings_currency_detail_content_card_country_price_rounding_modal %}
                <sw-settings-currency-country-modal
                    v-if="currentCurrencyCountry"
                    :currency-country-rounding="currentCurrencyCountry"
                    @save="onSaveCurrencyCountry"
                    @edit-cancel="onCancelEditCountry"
                />
                {% endblock %}
                {% endblock %}

                {% block sw_settings_currency_detail_custom_field_sets %}
                <mt-card
                    v-if="showCustomFields"
                    position-identifier="sw-settings-currency-detail-custom-field-sets"
                    :title="$tc('sw-settings-custom-field.general.mainMenuItemGeneral')"
                    :is-loading="isLoading"
                >
                    <sw-custom-field-set-renderer
                        :entity="currency"
                        :disabled="!acl.can('currencies.editor')"
                        :sets="customFieldSets"
                    />
                </mt-card>
                {% endblock %}
            </template>
        </sw-card-view>
    </template>
    {% endblock %}
</sw-page>
{% endblock %}
